#ifndef STR_UTILS_H
#define STR_UTILS_H

#include <string.h>
#include <ctype.h>

namespace pot {

inline void ToLower(char *str) {
  while (*str != '\0') {
    *str = tolower(*str);
    ++str;
  }
}

inline bool ContainsNonLetter(const char *str) {
  while (*str != '\0') {
    if (!isalpha(*str++)) return true;
  }
  return false;
}

template<typename T>
inline T *skip(T *p, int n) {
  for (int i = 0; i < n; ++i) {
    p += strlen(p) + 1;
  }
  return p;
}

inline int wordncmp(const char *p, const char *q, int n) {
  for ( ; *p == *q; ++p, ++q) {
    if (*p == 0 && --n == 0) return 0;
  }
  return *p - *q;
}


class WordsCmp {
public:
  WordsCmp(int k) : k_(k) { }
  bool operator()(const char *p, const char *q) {
    return wordncmp(p, q, k_) < 0;
  }
private:
  int k_;
};
} // pot

#endif // STR_UTILS_H
